<template>
	<view>
		<cu-custom :isBack="true">
			<block slot="backText"></block>
		</cu-custom>
		<view class="cu-list menu sm-border card-menu margin-top">
			<view class="cu-item" v-for="(item,index) in userLoginLogList" :key="index">
				<view :class="[item.loginType === 'wxApp' ? 'cuIcon-weixin' :'cuIcon-people' ]" class="lg"
					:style="[{color:themeConfig.primaryColor}]"
					style="width: 50px;height: 50px;line-height: 50px;font-size: 30px;"></view>
				<view class="content padding-tb-sm">
					<view class="flex justify-between">
						<view>{{item.auth}} </view>
						<view class="text-gray text-sm">{{formatDateTime(item.createdDate)}}</view>
					</view>
					<view class=text-sm>
						{{item.address}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		formatDateTime
	} from '@/util/formatTime.js'
	import * as authUserLoginLogApi from '@/api/auth/authUserLoginLog.js'
	import * as storage from '@/util/storage.js'
	export default {
		data() {
			return {
				currentPage: 1,
				total: 0,
				pageSize: 50,
				userId: storage.getUserId(),
				startDate: 0,
				endDate: 0,
				userLoginLogList: []
			}
		},
		computed: {
			themeConfig() {
				return this.$store.state.themeConfig
			}
		},
		created() {
			const timestamp = new Date().getTime()
			this.startDate = timestamp - 7 * 24 * 60 * 60 * 1000
			this.endDate = timestamp + 4 * 60 * 60 * 1000
			this.pageGetUserLoginLog()
		},
		methods: {
			formatDateTime(timestamp) {
				return formatDateTime(timestamp, this.$t('unKnow'))
			},
			pageGetUserLoginLog() {
				authUserLoginLogApi.pageGetUserLoginLog({
					pageSize: this.pageSize,
					currentPage: this.currentPage,
					startDate: Math.round(this.startDate / 1000),
					endDate: Math.round(this.endDate / 1000),
					userId: this.userId,
					loginType: this.loginType
				}).then(res => {
					const {
						data
					} = res
					if (data) {
						this.total = data.total
						this.userLoginLogList = data.data
					}
				})
			}
		}
	}
</script>

<style>

</style>
